package com.fu.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 付大大
 * @description
 * @create 2021-01-23 20:35
 */
public class ServletContextDemo extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = getServletContext();
        String globalDesc = context.getInitParameter("globalDesc");
        System.out.println(globalDesc);

        String contextPath = context.getContextPath();
        System.out.println(contextPath);

        String realPath = context.getRealPath("/");
        System.out.println(realPath);


        String b = context.getRealPath("/b.txt");
        System.out.println(b);

        String c = context.getRealPath("/WEB-INF/c.txt");
        System.out.println(c);

        String a = context.getRealPath("/WEB-INF/classes/a.txt");
        System.out.println(a);


        context.setAttribute("username","zhangsan");


        context.removeAttribute("username");


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
